import { ApiCall } from "tsrpc";
import { ReqDestroy, ResDestroy } from "../../../../shared/master/body/pet/PtlDestroy";
import { player } from "../../../../model/fight/body/player";
import { template } from "../../../../shared/master/MsgAction";

export default async function (call: ApiCall<ReqDestroy, ResDestroy>) {
    call.succ({})
    let user = call.req._player as player;
    let pets = user.getPets();
    let rms = pets.filter((e)=>{
        return e.name == call.req.name
    })
    if(rms.length == 0){
        user.sendMsg(template.default,`宠物放生:你没有叫${call.req.name}的宠物噢`)
        return;
    }
    if(rms.length > 1){
        user.sendMsg(template.default,`宠物放生:你有多个叫${call.req.name}的宠物,请给宠物改名后再试`)
        return;
    }
    let idx = pets.findIndex((e)=>{
        return e.name == call.req.name
    })
    user.sendMsg(template.default,`宠物${rms[0].name}已放生`)
    user.pets.splice(idx, 1);
    // TODO放生的宠物放到格子上
    const _cell = user.getPosition();
    _cell.add(rms[0])
}